<?php

function send_load_register_profile()
{
   if(isset($_SESSION['logged_in']) && $_SESSION['permissions'] == 'Student')
      return true;
   else
      return false;
}

function send_menu_register_profile()
{
   return "<br><a href=?q=register_profile>Register Profile</a>";
}

function send_content_register_profile()
{
   if(isset($_GET['q']))
   {
      if($_GET['q'] == "register_profile")
      {
         $query = "select f_name,uid from login_details where permissions = 'Faculty'";
         $result = query_db($query);

         $faculty = "<select name='Faculty'>";
         while($row = mysql_fetch_array($result, MYSQL_NUM))
         {
            $faculty .= "<option name='$row[1]' value='$row[1]'>$row[0], $row[1]</option>";
         }
         $faculty .= "</select><br><br>";

         $content =	
                        '
                        <script language="JavaScript" src="include/calendar/jquery-1.3.2.min.js"></script>
                        <script language="JavaScript" src="include/calendar/cal.js"></script>
                        <script language="JavaScript" src="include/calendar/cal2.js"></script>

			<form name="user_register" action="?q=register_profile_submit" method="post">
			*Name:<br>
			<input name="name" type="text" size="30" maxlength="30"><br><br>	
			*D_O_B:<br>
		        <input class="one" type="text" name="D_O_B" value="" /><br><br>
			*Faculty:<br>';
         $content =     $content.$faculty.
                        ' 
			*Department:<br>
			<input name="Department" type="text" size="30" maxlength="30"><br><br>
			*Project_Title:<br>
			<input name="Project_Title" type="text" size="30" maxlength="30"><br><br>
			<input type="submit" value="Submit" />
			</form>';
         		return $content;    
      }
      else if($_GET['q'] == "register_profile_submit")
        
      {
         global $db_agent;

         if($db_agent == "mysql")
         {
            
            $user_first_name = $_POST['name'];
            if(strlen($user_first_name)>20)
               return "Please dont hack";
            $d_o_b= $_POST['D_O_B'];
            if($d_o_b == "")
            return "Date of birth is mandatory";
            
            $d_o_b = preg_split("/\//",$d_o_b,-1,PREG_SPLIT_OFFSET_CAPTURE);
            $date = $d_o_b[1][0];
            $month = $d_o_b[0][0];
            $year = $d_o_b[2][0];

            $Faculty = $_POST['Faculty'];
            $Department = $_POST['Department'];
	    $Project_Title = $_POST['Project_Title'];			  

            $query = "update students set f_name = '$user_first_name', d_o_b = '$year-$month-$date', faculty = '$Faculty', department = '$Department', project_title = '$Project_Title' where uid = $_SESSION[user_name] ";
            $result = query_db($query);
            if(!$result)
               return "Problem with SQL";

            return "Profile Updated";
         }
       }
   		}
	}

function send_content_other_register_profile()
{

}

?>
